//
//  UIImage+OMTUIKit.swift
//  OMTUIKitSwift
//
//  Created by 昭荣伊 on 2018/12/10.
//

import Foundation

extension UIImage {
    
    /// 通过颜色创建图片
    ///
    /// - Parameter color: 颜色
    public convenience init(_ color: UIColor) {
        let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
        UIGraphicsBeginImageContext(rect.size)
        if let context = UIGraphicsGetCurrentContext() {
            context.setFillColor(color.cgColor)
            context.fill(rect)
        }
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        
        if let cgImage = image?.cgImage {
            self.init(cgImage: cgImage)
        } else {
            self.init()
        }
    }
}
